package com.sqstudio.exercise.chapter4{
	
	import flash.events.Event;
	
	import org.papervision3d.events.FileLoadEvent;
	import org.papervision3d.materials.BitmapFileMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;

	[SWF(width="800",height="600")]
	
	/**
	 *材质平铺 
	 * @author Nestor
	 * 
	 */	
	public class MaterialTiling extends BasicView
	{
		public function MaterialTiling(viewportWidth:Number=800, viewportHeight:Number=600, scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String="Target")
		{
			super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
			stage.frameRate = 40;
			init();
			this.startRendering();
		}
		
		private function init():void{
			var material:BitmapFileMaterial = new BitmapFileMaterial("assets/2.png");
			material.addEventListener(FileLoadEvent.LOAD_COMPLETE,picComHandler);
			var plane:Plane = new Plane(material,478,114,5,4);
			scene.addChild(plane);
		}
		
		private function picComHandler(e:Event):void
		{
			// TODO Auto-generated method stub
			var material:BitmapFileMaterial = BitmapFileMaterial(e.target);
			material.tiled = true;
			material.maxU = 2;
			material.maxV = 2;
		}
		
		override protected function onRenderTick(event:Event=null):void
		{
			super.onRenderTick(event);
		}
	}
}